import $ from 'jquery'
import ajax from '../../utils/ajax'

const form = document.forms.modifyPwd;

// form.onsubmit = async function (e) {
//     e.preventDefault();
//     if (confirm('您确定修改吗')) {

//     }
// }
$('form[name="modifyPwd"]').on("submit", async function (e) {
    e.preventDefault();
    const newPwd = $('[name="newPwd"]').val()
    const newPwd2 = $('[name="newPwd2"]').val()
    const oldPwd = $('[name="oldPwd"]').val()
    if (newPwd == '' || newPwd != newPwd2) {
        alert('两次密码输入不一致！')
        return;
    }
    if (oldPwd == "") {
        alert('旧密码必须输入')
        return;
    }
    const result = await ajax('post', '/api/manage/modifyPwd', { oldPwd, newPwd })

    alert(result.msg)
    if (result.flag) {
        //正确则重新登录
        //删除本地token
        // localStorage.removeItem('token');
        //跳转到登录页，top是顶级页面，受token影响光写location不会跳转
        top.location.assign('/manage/login.html')
    }
})